﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CE.Database;
using CE.Global;

public partial class car_insurance_CompareInsurance : MyLanguageAndSessionBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["CITempResultId"] != null && Session["CITempResultId"].ToString() != "")
            {
                BindRptCompare();
            }
            else
            {
                Response.Redirect(CE.Global.General.GetUrl("~/car-insurance/car-details.aspx", Page));
            }
        }
    }

    private void BindRptCompare()
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblCarModel");
        SortedList _spList = new SortedList();
        _spList.Add("@CarResultIdList", Session["CITempResultId"].ToString());
        _dt = _db.GetDataTableBySP("sprocGetCompareInsuranceListByTempId", _spList);
        if (_dt != null && _dt.Rows.Count > 0)
        {
            rptCompare.DataSource = _dt;
            rptCompare.DataBind();
        }

        _dt = null;
        _db = null;
    }
    protected void rptCompare_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        Label lblProviderId = (Label)e.Item.FindControl("lblProviderId");
        Label lblTempResultId = (Label)e.Item.FindControl("lblTempResultId");
        string _redirectUrl;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
        }
        if (e.CommandName.ToLower().Equals("buynow"))
        {
            Session[CE.Global.General.ProviderCompanyId] = lblProviderId.Text;
            Session[CE.Global.General.CarResultId] = lblTempResultId.Text;
            _redirectUrl = SetBuyNowUrl(lblProviderId.Text);
                Response.Redirect(_redirectUrl);
        }
        else if (e.CommandName.ToLower().Equals("moreinfo"))
        {
            Session[CE.Global.General.ProviderCompanyId] = lblProviderId.Text;
            Session[CE.Global.General.CarResultId] = lblTempResultId.Text;

            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/quote-details.aspx", Page);
            Response.Redirect(_redirectUrl);

        }
    }

    protected void rptCompare_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType ==  ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            
            HtmlImage imgSpecial = (HtmlImage)e.Item.FindControl("imgSpecial");
            HtmlGenericControl divSpecialNCB = (HtmlGenericControl)e.Item.FindControl("divSpecialNCB");
            Label lblPackageName = (Label)e.Item.FindControl("lblPackageName");
            if (lblPackageName.Text == "GluayGluay.com Special")
            {
                divSpecialNCB.Style.Add("display", "");
                imgSpecial.Style.Add("display", "");
            }
        
        }
        Repeater ss = (Repeater)sender;
        
    }

    public string SetBuyNowUrl(string providerid)
    {
        string _redirectUrl = string.Empty;
        if (providerid == "11")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/azcp_proposal_form.aspx", Page);
        }
        else if (providerid == "12")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/msig_proposal_form.aspx", Page);
        }
        else if (providerid == "16")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/axa_proposal_form.aspx", Page);
        }
        else if (providerid == "29")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/lmg_proposal_form.aspx", Page);
        }
        else if (providerid == "31")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/chartis_proposal_form.aspx", Page);
        }
        else if (providerid == "32")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/bki_proposal_form.aspx", Page);
        }
        else if (providerid == "33")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/mti_proposal_form.aspx", Page);
        }
        else if (providerid == "35")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/krungthai_proposal_form.aspx", Page);
        }
        else if (providerid == "39")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/mittare_proposal_form.aspx", Page);
        }
        else if (providerid == "41")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/ksk_proposal_form.aspx", Page);
        }
        else if (providerid == "43")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/synmunkong_proposal_form.aspx", Page);
        }
        else if (providerid == "45")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/viriyah_proposal_form.aspx", Page);
        }
        else if (providerid == "46")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/tms_proposal_form.aspx", Page);
        }
        else if (providerid == "50")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/scsmg_proposal_form.aspx", Page);
        }
        else if (providerid == "58")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/tvv_proposal_form.aspx", Page);
        }
        else if (providerid == "65")
        {
            _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/proposalforms/dhipaya_proposal_form.aspx", Page);
        }
        return _redirectUrl;
    }
}
